<template>
  <div class="wrapper" ref="wrapper">
    <div class="content" ref="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'

  export default{
    name:'',
    data(){
      return {
          scroll:null
       }
    },
    props:{
      probeType:{
        type:Number,
        default:3
      },
      pullUpLoad:{
        type:Boolean,
        default:true
      }
    },
    mounted() {
      this.scroll=new BScroll(this.$refs.wrapper,{
        probeType:this.probeType,
        pullUpLoad:this.pullUpLoad,
        observeDOM:true,
        click:true,
        scrollY:true,
        mouseWheel:true
      })

      if(this.probeType===2||this.probeType===3){
        this.scroll.on('scroll',position=>{
          this.$emit('tabShow',position)
          this.$emit('sendOrdinate',position)
        })
      }

      if(this.pullUpLoad){
        this.scroll.on('pullingUp',()=>{
          this.$emit('addPage')
        })
      }

    },
    methods:{
      scrollTo(x,y,time=1000){
        this.scroll&&this.scroll.scrollTo(x,y,time)
      },
      finishPullUp(){
        this.scroll&&this.scroll.finishPullUp()
      },
      refresh(){
        this.scroll&&this.scroll.refresh()    //防止img加载比bscroll快导致出错
      },
      getY(){
        return  this.scroll.y
      }
    },
    components:{

    }
  }
</script>

<style scoped>

</style>
